package carson.web.mvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 通过重定向到指定的 URI 来控制对应用程序操作的处理
 *
 * @author Carson Chen
 */
public class RedirectResult extends AbstractResult {

    /**
     * 实例化RedirectResult
     *
     * @param url 重定向到的url
     */
    public RedirectResult(String url) {
        this.url = url;
    }

    private String url;

    /**
     * 获取url.
     *
     * @return url
     */
    public String getUrl() {
        return url;
    }

    @Override
    public void executeResult(HttpServletRequest request, HttpServletResponse response) {
        try {
            response.sendRedirect(this.url);
        } catch (IOException ex) {

        }
    }
}
